package com.ctshk.rpc.cms.mapper;

import com.ctshk.rpc.cms.entity.ContentClassification;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * <p>
 * 内容分类 Mapper 接口
 * </p>
 *
 * @author LiZhiming
 * @since 2021-04-23
 */
public interface ContentClassificationMapper extends BaseMapper<ContentClassification> {

    @Update("update t_content_classification set status = #{status} where id=#{id}")
    int updateStatusById(@Param("id") Long id, @Param("status") Integer status);

    @Select("SELECT *  FROM (SELECT t1.id,t1.parent_id,t1.classification_name,t1.STATUS,\n" +
            "IF ( find_in_set( parent_id, @pids ) > 0, @pids := concat( @pids, ',', id ), 0 ) AS ischild \n" +
            "FROM ( SELECT id, parent_id, classification_name, STATUS FROM t_content_classification t WHERE t.is_deleted = 0 ORDER BY parent_id, id ) t1,\n" +
            "\t(SELECT @pids := #{patenId} ) t2 ) t3\n" +
            "WHERE ischild != 0;")
    List<ContentClassification> getLevelQuery(@Param("patenId") Long patenId);
}
